home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************
- * *
- * TubeSavr.pas: Plug-in animation module for SSaveDem.pas *
- * *
- * Rev. 0.1 19.4.93 MK IR *
- * *
- ****************************************************************************}
-
- { Name for this Screen Saver - shows up in Control Panel: }
- {$D SCRNSAVE Tubes }
-
- const AppName: PChar = 'Screen Saver.Tubes' ;
-
- type
- PMySaverWin = ^TMySaverWin;
- TMySaverWin = Object(TScSaverWin)
- zx, zy, cx, cy, vx, vy, d: integer;
- NewBrush: hBrush;
- constructor Init (aParent:PWindowsObject; aTitle:PChar);
- procedure DoTheShow; virtual;
- destructor Done; virtual;
- end;
-
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . I n i t *
- * *
- * OUTPUT: zx, zy = screen dimensions *
- * vx, vy = speed of circle *
- * cx, cy = starting position *
- * d = circle diameter (all of the above in pixels) *
- * NewBrush = brush with random solid color *
- * *
- ****************************************************************************}
-
- constructor TMySaverWin.Init;
-
- var color: TColorRef;
- TheDC: hDC;
-
- begin
- inherited Init (aParent, aTitle);
- randomize;
- zx := GetSystemMetrics (SM_CXSCREEN) ;
- zy := GetSystemMetrics (SM_CYSCREEN) ; { get screen dimensions }
- cx := random (zx div 2) + 1;
- cy := random (zy div 2) + 1; { get starting position }
- vx := 2*(random (2)+1);
- vy := 2*(random (2)+1); { get speed }
- d := zy div 8; { diameter }
-
- TheDC := TestHandle (GetDC (hWindow));
- color := GetNearestColor (TheDC, rgb (random(256), random(256), random(256)));
- if (color = 0) then color := $FFFFFF; { black on black would be boring }
- NewBrush := TestHandle (CreateSolidBrush (color));
- ReleaseDC (hWindow, TheDC);
-
- end; { Init }
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . D o T h e S h o w *
- * *
- * INPUT: zx, zy = screen dimensions *
- * vx, vy = actual speed *
- * cx, cy = actual position *
- * d = circle diameter (all of the above in pixels) *
- * NewBrush = brush with color to use *
- * *
- * OUTPUT: vx, vy = new speed of circle *
- * cx, cy = new position *
- * NewBrush = brush, maybe with new random solid color *
- * *
- ****************************************************************************}
-
- procedure TMySaverWin.DoTheShow ;
-
- var TheDC: hDC;
- OldBrush: hBrush;
- color: TColorRef;
-
- begin
- TheDC := TestHandle (GetDC (hWindow));
- if ((cx <= 0) or (cx+d >= zx)) then vx := -vx; { bounce circle at edges }
- if ((cy <= 0) or (cy+d >= zy)) then vy := -vy;
- cx := cx+vx; { calculate new position }
- cy := cy+vy;
-
- if ((abs (zx div 2 - cx) < zx div 32)
- and (abs (zy div 2 - cy) < zy div 32)) then { if at center of screen,}
- begin { change color: }
- DeleteObject (NewBrush);
- color :=rgb (random(256), random(256), random(256));
- NewBrush := TestHandle (CreateSolidBrush (GetNearestColor (TheDC, color)));
- end;
- OldBrush := TestHandle (SelectObject (TheDC, NewBrush));
- Ellipse (TheDC, cx, cy, cx+d, cy+d); { paint circle }
- TestHandle (SelectObject (TheDC, OldBrush));
-
- ReleaseDC (hWindow, TheDC);
- end; { DoTheShow }
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . D o n e *
- * *
- ****************************************************************************}
-
- destructor TMySaverWin.Done; { cleans up }
- begin
- DeleteObject (NewBrush);
- inherited done;
- end;
-
-
-
-